package com.easybbs.mappers;

import com.easybbs.entity.po.NewsPO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface NewsMapper<T, P> extends BaseMapper<T, P> {

    @Insert("insert into  news (mainTitle,subTitle,pos,weight,tag,img,content,ctime)" +
            " value (#{newPO.mainTitle},#{newPO.subTitle},#{newPO.pos},#{newPO.weight},#{newPO.tag},#{newPO.img},#{newPO.content},#{newPO.ctime})")
    void insertNews(@Param("newPO") NewsPO newsPO);

    @Select("select * from news limit 0,1")
    NewsPO selectNews();

    @Select("select id,mainTitle,tag from news where pos='main' order by weight limit 0,3")
    List<NewsPO> selectMainNews();

    @Select("select  * from  news where id=#{newsId}")
    NewsPO selectSingleNews(@Param("newsId") int newsId);

    @Select("select id,mainTitle,tag from news where pos='center1' order by weight limit 0,17")
    List<NewsPO> selectCenter1();

    @Select("select id,mainTitle,tag,img from news where pos='center2' order by weight limit 0,4")
    List<NewsPO> selectCenter2();

    @Select("select id,mainTitle,tag,img from news where pos='right' order by weight limit 0,8")
    List<NewsPO> selectRight();

    @Select("select id,mainTitle,ctime from news where pos='bottom1' order by weight limit 0,5")
    List<NewsPO> selectBottom1();

    @Select("select id,mainTitle,ctime from news where pos='bottom2' order by weight limit 0,5")
    List<NewsPO> selectBottom2();

    @Select("select id,mainTitle,ctime from news where pos='bottom3' order by weight limit 0,5")
    List<NewsPO> selectBottom3();

    @Select("select id,mainTitle from news where pos='bottom4' order by weight limit 0,7")
    List<NewsPO> selectBottom4();
}
